package com.dyzx.hbb.modules.sys.controller;

import com.dyzx.hbb.common.base.Result;
import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.common.controller.BaseController;
import com.dyzx.hbb.modules.sys.entity.SysParam;
import com.dyzx.hbb.modules.sys.query.ParamQuery;
import com.dyzx.hbb.modules.sys.service.SysParamService;
import com.dyzx.hbb.modules.sys.vo.ParamUVO;
import com.dyzx.hbb.modules.sys.vo.ParamVO;
import com.dyzx.hbb.security.context.SecurityContextHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/sys/param")
@RestController
@Tag(name = "08.参数管理", description = "参数相关接口")
public class ParamController extends BaseController<SysParamService, SysParam, ParamQuery, ParamVO, ParamUVO> {

    @Autowired
    private SysParamService service;



    @Override
    protected SysParamService getBaseService() {
        return service;
    }



    @Override
    protected MyLambdaQueryWrapper<SysParam> queryWrapper(ParamQuery query) {
        if (query != null) {
            Long organId = SecurityContextHolder.getOrganId();
            MyLambdaQueryWrapper<SysParam> wrapper = new MyLambdaQueryWrapper<>();
            wrapper.select(SysParam::getId, SysParam::getName, SysParam::getStatus,SysParam::getCreateDate, SysParam::getUpdateDate, SysParam::getRemark, SysParam::getKeyStr, SysParam::getValue);
            wrapper.eq(query.getKey_str() != null,SysParam::getKeyStr, query.getKey_str())
                    .like(StringUtils.isNotBlank(query.getName()), SysParam::getName, query.getName());

            return wrapper;
        } else {
            return null;
        }

    }

    @Override
    protected MyLambdaQueryWrapper<SysParam> queryInfoWrapper() {
        MyLambdaQueryWrapper<SysParam> wrapper = new MyLambdaQueryWrapper<>();
        wrapper.select(SysParam::getId, SysParam::getName, SysParam::getStatus,SysParam::getCreateDate, SysParam::getUpdateDate, SysParam::getRemark, SysParam::getKeyStr, SysParam::getValue);
        return wrapper;
    }



}
